<?php
set_time_limit(0);
ob_start();
global $conn;
$conn = ftp_connect("localhost",'21') or die("Could not connect");
ftp_login($conn,"test","123456");

/*echo '<pre>';
 print_r(ftp_nlist($conn,"public_html"));
 echo '</pre>';*/


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery Drop Down Menu</title>

<!-- CSS For The Menu -->
<link rel="stylesheet" href="style.css" />

</head>
<body>

<!-- Menu Start -->
<div id="jQ-menu"><?php
$path = './mysoha/';
//echo '<pre>';
//print_r(ftp_nlist($conn,"public_html"));
//echo '</pre>';

/*for($i=0,$dir = ftp_nlist($conn,".");$i<count($dir);$i++){
 $file = substr($dir[$i], strrpos($dir[$i],'/') + 1);
 echo $file;
 }*/


function createDir($path = '.')
{
	global $conn;
	echo "<ul>";
	for($i=0,$dir = ftp_nlist($conn,$path);$i<count($dir);$i++){
		$file = substr($dir[$i], strrpos($dir[$i],'/') + 1);
		if (strrpos($file,'.') === false){
			//echo '<li>'.$file.'</li>';
			printSubDir($file, $path, $queue);
		}else{
			//echo '<li>---'.$file.'</li>';
			$queue[] = $file;
		}
		unset($file);
	}
	printQueue($queue, $path);
	unset($queue,$path);
	echo "</ul>";
	flush();
	ob_flush();
}

function printQueue($queue, $path)
{
	foreach ($queue as $key => $file)
	{
		//die($file.'--'.$path);
		printFile($file, $path);
		unset($queue[$key]);
	}
	unset($queue);
}

function printFile($file, $path)
{
	echo "<li><a href=\"".$path.$file."\">$file</a></li>";
	flush();
	ob_flush();
}

function printSubDir($dir, $path)
{
	echo "<li><span class=\"toggle\">$dir</span>";
	//die($path.$dir."/----");
	createDir($path.$dir."/");
	echo "</li>";
	flush();
	ob_flush();
}

createDir($path);
?></div>
<!-- End Menu -->


<!-- Add jQuery From the Google AJAX Libraries -->
<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

<!-- jQuery Color Plugin -->
<script type="text/javascript" src="jquery.color.js"></script>

<!-- Import The jQuery Script -->
<script type="text/javascript" src="jMenu.js"></script>
<?php ftp_close($conn);?>
</body>
</html>
